package com.example.demo.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.example.demo.core.CPUCore;


/**
 * @author Administrator
 * 线程池工具类
 */
public class ThreadPoolUtil {
	
	private static ExecutorService threadPool;
	
	/*public static ExecutorService getThreadPool() {
		
		if(null==threadPool) {
			//根据cpu核心数获取最佳线程数
			threadPool = Executors.newFixedThreadPool(CPUCore.getBestThreadNum());
		}
		
		return threadPool;
	}*/
	
	public static ExecutorService getThreadPool() {
		
		if(null==threadPool) {
			threadPool = new ThreadPoolExecutor(2, CPUCore.getBestThreadNum(), 20, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>());
		}
		
		return threadPool;
	}
}
